from docx import Document
from docx.shared import Inches

def resize_images_in_word(doc_path, output_path, target_width_cm, target_height_cm):
    doc = Document(doc_path)
    target_width_emu = int(target_width_cm * 360000)  # 1厘米 = 360000 EMU
    target_height_emu = int(target_height_cm * 360000)

    for shape in doc.inline_shapes:
        shape.width = target_width_emu
        shape.height = target_height_emu

    doc.save(output_path)

if __name__ == "__main__":
    input_doc = 'D:\opt\zpj.docx'
    output_doc = 'D:\opt\zpj_out.docx'
    width_cm = 7
    height_cm = 4
    resize_images_in_word(input_doc, output_doc, width_cm, height_cm)

